@import '~@hi-ui/core-css/lib/index.scss';

$prefix: '#{$component-prefix}-modal' !default;

$box-shadow-primary: 0 1px 6px rgba(0, 0, 0, 0.2) !default;
$modal-overlay-background-color: rgba(0, 0, 0, 0.45) !default;

.#{$prefix} {
  @include flex;

  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: use-zindex('modal');
  overflow: hidden;

  &__overlay {
    @include flex;

    position: absolute;
    top: 0;
    left: 0;
    z-index: use-zindex('back');
    width: 100%;
    height: 100%;
    background-color: $modal-overlay-background-color;

    // animation
    transition-timing-function: use-motion-bezier('normal');
    transition-duration: use-motion-duration('slow');
    transition-property: opacity;
    opacity: 0;
    pointer-events: none;

    .#{$prefix}--motion-enter & {
      opacity: 0;
    }

    .#{$prefix}--motion-enter-active & {
      opacity: 1;
    }

    .#{$prefix}--motion-enter-done & {
      opacity: 1;
      pointer-events: all;
    }

    .#{$prefix}--motion-exit & {
      opacity: 1;
    }

    .#{$prefix}--motion-exit-active & {
      opacity: 0;
    }

    .#{$prefix}--motion-exit-done & {
      opacity: 0;
      pointer-events: none;
    }
  }

  &__wrapper {
    position: relative;
    min-width: 20%;
    min-height: 18px;
    background: use-color-static('white');
    border-radius: use-border-radius('lg');
    box-shadow: use-shadow('lg');
    transition: use-motion-duration('slow') use-motion-bezier('normal');
    display: flex;
    flex-direction: column;

    // animation
    transition-timing-function: use-motion-bezier('normal');
    transition-duration: use-motion-duration('slow');
    transition-property: all;
    opacity: 0;
    transform: scale(0);
    will-change: transform;

    .#{$prefix}--size-sm & {
      width: 400px;
    }

    .#{$prefix}--size-md & {
      width: 520px;
    }

    .#{$prefix}--size-lg & {
      width: 720px;
    }

    .#{$prefix}--motion-enter & {
      opacity: 0;
      transform: scale(0.5);
    }

    .#{$prefix}--motion-enter-active & {
      opacity: 1;
      transform: scale(1);
    }

    .#{$prefix}--motion-enter-done & {
      opacity: 1;
      transform: scale(1);
    }

    .#{$prefix}--motion-exit & {
      opacity: 1;
      transform: scale(1);
    }

    .#{$prefix}--motion-exit-active & {
      opacity: 0;
      transform: scale(0.5);
    }

    .#{$prefix}--motion-exit-done & {
      opacity: 0;
      transform: scale(0);
      transition-property: none;
    }
  }

  &__close {
    position: absolute;
    right: 8px;
    font-size: 18px;
    cursor: pointer;
    background-color: transparent;
  }

  &__header {
    box-sizing: border-box;
    font-size: use-text-size('lg');
    font-weight: use-text-weight('semibold');
    line-height: use-text-lineheight('normal');
    color: use-color('gray', 700);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    padding: calc(#{use-spacing(8)} - 1px) use-spacing(12);

    &--divided {
      border-bottom: use-border-size('normal') use-color('gray', 200);
    }

    .#{$prefix}__close-button {
      margin-inline-start: auto;
    }
  }

  &__title {
    flex: 1;
    display: flex;
    align-items: center;
    font-size: use-text-size('lg');
  }

  &__body {
    box-sizing: border-box;
    overflow: auto;
    flex: 1;
    padding: use-spacing(10) use-spacing(12);
    font-size: use-text-size('normal');
    color: use-color('gray', 700);
  }

  &__icon {
    font-size: 24px;
    margin-inline-end: use-spacing(4);
  }

  &--type {
    &-success {
      .#{$prefix}__icon {
        color: use-color-mode('success');
      }

      .#{$prefix}__body {
        padding-top: use-spacing(2);
      }
    }

    &-error {
      .#{$prefix}__icon {
        color: use-color-mode('danger');
      }

      .#{$prefix}__body {
        padding-top: use-spacing(2);
      }
    }

    &-warning {
      .#{$prefix}__icon {
        color: use-color-mode('warning');
      }

      .#{$prefix}__body {
        padding-top: use-spacing(2);
      }
    }

    &-info {
      .#{$prefix}__icon {
        color: use-color-mode('primary');
      }

      .#{$prefix}__body {
        padding-top: use-spacing(2);
      }
    }
  }

  &__footer {
    box-sizing: border-box;
    padding: 0 use-spacing(12) use-spacing(12);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    flex-shrink: 0;
    position: relative;

    &--divided {
      &::before {
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        content: '';
        display: block;
        width: 100%;
        margin-top: -32px;
        height: 32px;
        background: linear-gradient(180deg, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 1) 100%);
        pointer-events: none;
      }
    }
  }
}
